<template>
  <div class="notice-detail-container">
    <!-- 页面标题区域 -->
    <el-page-header @back="goBack" :content="notice.name" class="page-header">
    </el-page-header>

    <!-- 公告详情卡片 -->
    <el-card class="notice-card" shadow="hover">
      <div slot="header" class="clearfix">
        <span class="notice-title">{{ notice.name }}</span>
        <span class="notice-date">{{ notice.current }}</span>
      </div>

      <div style="width: 80%;margin: 0 auto;">
        <el-descriptions :column="1" class="notice-meta">
          <el-descriptions-item label="发布时间">
            <el-tag type="info" size="small">{{ notice.current }}</el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="公告类型">
            <el-tag :type="getNoticeTypeTag(notice.type)" size="small">
              {{ notice.type }}
            </el-tag>
          </el-descriptions-item>
        </el-descriptions>
      </div>

      <el-divider></el-divider>

      <div class="notice-content">
        <div style="width: 86%;margin: 0 auto;">
          <v-md-editor
              v-model="notice.content"
              mode="preview"
              height="auto"
              class="markdown-content">
          </v-md-editor>
        </div>

      </div>
    </el-card>
  </div>
</template>

<script>
import api from "@/api";

export default {
  name: "NoticeDetail",
  data() {
    return {
      notice: {
        id: 1,
        name: "加载中...",
        content: "",
        user: "",
        type: "",
        date: ""
      }
    };
  },
  mounted() {
    this.fetchNoticeDetail();
  },
  methods: {
    // 返回上一页
    goBack() {
      this.$router.go(-1);
    },
    // 获取公告详情
    async fetchNoticeDetail() {
      const id = this.$route.query.id;
      try {
        const response = await api.notice.noticeId(id);
        this.notice = response.data.data;
      } catch (error) {
        this.$message.error('获取公告详情失败');
        console.error(error);
      }
    },
    // 根据公告类型获取标签样式
    getNoticeTypeTag(type) {
      const typeMap = {
        '系统通知': 'primary',
        '重要公告': 'danger',
        '活动通知': 'success',
        '维护公告': 'warning',
        '其他': 'info'
      };
      return typeMap[type] || 'info';
    }
  }
};
</script>

<style scoped>
.notice-detail-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 60px);
}

.page-header {
  margin-bottom: 30px;
  padding-bottom: 15px;
  border-bottom: 1px solid #ebeef5;
}

.header-content h1 {
  margin: 0;
  font-size: 24px;
  color: #303133;
}

.subtitle {
  margin: 5px 0 0;
  font-size: 14px;
  color: #909399;
}

.notice-card {
  border-radius: 8px;
  transition: all 0.3s;
}

.notice-card:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.notice-title {
  font-size: 20px;
  font-weight: bold;
  color: #303133;
}

.notice-type-tag {
  margin-left: 10px;
}

.notice-date {
  float: right;
  font-size: 14px;
  color: #909399;
  line-height: 28px;
}

.notice-content {
  padding: 10px 0;
}

.markdown-content {
  font-size: 15px;
  line-height: 1.8;
  color: #606266;
}

.notice-meta {
  margin-top: 20px;
}

.notice-meta >>> .el-descriptions-item__label {
  width: 100px;
  font-weight: bold;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .notice-title {
    display: block;
    margin-bottom: 10px;
  }

  .notice-type-tag {
    margin-left: 0;
    margin-bottom: 10px;
  }

  .notice-date {
    float: none;
    display: block;
  }
}
</style>